<?php
echo date('m/d l H:i:s');
echo '<hr />';
$csdn = get_csdn();
echo '[CSDN]'.$csdn[0];
echo '<br />';
echo '[CSDN]'.$csdn[1];
echo '<hr />';
$qq = get_qq();
foreach ($qq as $row) {
	echo '[QQ]'.$row.'<br />';
}
echo '<hr/>';
$phpchina = get_phpchina();
foreach ($phpchina as $row) {
	echo '[PHPCHINA]'.$row.'<br />';
}

//get函数库
function get_csdn() {
	$content = file_get_contents('http://csdn.net/');
	$pattern = '/(?<=<h1 class="txt_black">).*(?=<\/h1>)/';
	preg_match_all($pattern, $content, $arr);
	
	return $arr[0];
}

function get_qq() {
	$content = file_get_contents('http://news.qq.com/');
	$content = iconv("GBK", "UTF-8", $content);
	$pattern = '/(?<=<h[24]>).*(?=<\/h[24]>)/';
	preg_match_all($pattern, $content, $arr);
	
	return $arr[0];
}

function get_phpchina() {
	$content = file_get_contents('http://www.phpchina.com/');
	$content = iconv("GBK", "UTF-8", $content);
	$pattern = '/(?<=<dt>).*(?=<\/dt>)/';
	preg_match_all($pattern, $content, $arr);

	return $arr[0];
}
?>